package Chitietcauhoi.backing;

import common.Utils;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import java.util.ResourceBundle;

import javax.faces.context.FacesContext;

import javax.portlet.PortletConfig;
import javax.portlet.PortletRequest;

import oracle.adf.model.binding.DCIteratorBinding;

import oracle.jbo.ViewCriteria;
import oracle.jbo.ViewObject;

public class ChitietcauhoiBean {
    private String hoidapId;
    private String tieudechitiet;
    private String viewRender;
    public ChitietcauhoiBean() {
        super();
    }

    public String getViewRender() {
        getHoidapId();
        getChiTietCauHoi();
        return viewRender;
    }
    
    private void getChiTietCauHoi(){
        DCIteratorBinding chitietIterator = Utils.getIteratorBinding("HoidapView1Iterator");
        ViewObject vo = chitietIterator.getViewObject();
        ViewCriteria vc =
            vo.getViewCriteriaManager().getViewCriteria("HoidapViewCriteria");
        vc.ensureVariableManager().setVariableValue("varId", hoidapId);
        vo.getViewCriteriaManager().removeViewCriteria("HoidapViewCriteria");
        vo.getViewCriteriaManager().applyViewCriteria(vc);
        vo.executeQuery();        
    }

    public String getNguoiGuiLabel() {
        String resource = getResource("NGUOI_GUI_LABLE");
        return resource;
    }

    public String getDiaChiLabel() {
        String resource = getResource("DIA_CHI_LABLE");
        return resource;
    }

    public String getDienThoaiLabel() {
        String resource = getResource("DIEN_THOAI_LABLE");
        return resource;
    }

    public String getTieuDeLabel() {
        String resource = getResource("TIEU_DE_LABLE");
        return resource;
    }

    public String getChuDeLabel() {
        String resource = getResource("CHU_DE_LABLE");
        return resource;
    }

    public String getNoiDungCauHoiLabel() {
        String resource = getResource("NOI_DUNG_CAU_HOI_LABLE");
        return resource;
    }

    public String getGuiCauHoiButton() {
        String resource = getResource("GUI_CAU_HOI");
        return resource;
    }

    public String getNhapLaiButton() {
        String resource = getResource("BO_QUA");
        return resource;
    }

    public String getNhapHoVaTen() {
        String resource = getResource("NHAP_HO_VA_TEN");
        return resource;
    }

    public String getNhapDiaChiMail() {
        String resource = getResource("NHAP_DIA_CHI_MAIL");
        return resource;
    }

    public String getNhapSaiDinhDangMail() {
        String resource = getResource("NHAP_SAI_DINH_DANG_MAIL");
        return resource;
    }

    public String getNhapTieuDe() {
        String resource = getResource("NHAP_TIEU_DE");
        return resource;
    }

    public String getChonChuDe() {
        String resource = getResource("CHON_CHU_DE");
        return resource;
    }

    public String getChonChuDeLable() {
        String resource = getResource("CHON_CHU_DE_LABLE");
        return resource;
    }

    public String getNhapNoiDung() {
        String resource = getResource("NHAP_NOI_DUNG");
        return resource;
    }

    public String getNgayGui() {
        String resource = getResource("NGAY_GUI_LABLE");
        return resource;
    }

    public String getCauTraLoi() {
        String resource = getResource("CAU_TRA_LOI_LABLE");
        return resource;
    }

    private String getResource(String resourceKey) {
        Locale locale = getPortalLocale();
        ResourceBundle bundle =
            ResourceBundle.getBundle("model.PortletsBundle", locale);
        return bundle.getString(resourceKey);
    }

    /**
     * Author       Date        Comment
     *  TớiNT    09/11/2012     Thêm mới
     * @return Kiểu ngôn ngữ
     */
    private Locale getPortalLocale() {
        Locale portalLocale = new Locale("vi", "VN");
        String language = "";
        try {

            PortletRequest request =
                (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            if (request.getParameter("ngonnguid") != null) {
                language = request.getParameter("ngonnguid");
                portalLocale = new Locale(language);
            }

        } catch (Exception e) {
            // TODO: Add catch code
            e.printStackTrace();
        }

        return portalLocale;
    }

    /**
     * Author       Date        Comment
     *  TớiNT    09/11/2012     Thêm mới
     * @return request param cauhoiid
     */
    private String cauhoiId() {
        String hoidapId = "";
        try {
            PortletRequest request =
                (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            if (request.getParameter("cauhoiid") != null)
                hoidapId = request.getParameter("cauhoiid").toString();
        } catch (Exception e) {
            // TODO: Add catch code
            e.printStackTrace();
        }

        return hoidapId;
    }

    private String TieudeCtcauhoi() {
        String tieudecauhoi = "Chi tiết nội dung câu hỏi";
        try {

            PortletRequest request =
                (PortletRequest)FacesContext.getCurrentInstance().getExternalContext().getRequest();
            if (request.getParameter("tieudechitiet") != null)
                tieudecauhoi = request.getParameter("tieudechitiet").toString();
        } catch (Exception e) {
            // TODO: Add catch code
            e.printStackTrace();
        }

        return tieudecauhoi;
    }

    public void setHoidapId(String hoidapId) {
        this.hoidapId = hoidapId;
    }

    public String getHoidapId() {
        hoidapId = cauhoiId();
        return hoidapId;

    }

    public void setTieudechitiet(String tieudechitiet) {
        this.tieudechitiet = tieudechitiet;
    }

    public String getTieudechitiet() {
        tieudechitiet = TieudeCtcauhoi();
        return tieudechitiet;
    }
}
